<?php

class Ynbusinesspages_Model_Package extends Core_Model_Item_Abstract {
    protected $_searchTriggers = false;
    
    public function getTitle() {
        return $this->title;
    }
    
    public function isViewable() {
        return $this->authorization()->isAllowed(null, 'view');
    }
	
	public function checkHasBusiness(){
		return true;
	}
    
    public function getAvailableFeatures() {
        $title = array();
        $view = Zend_Registry::get('Zend_View');
        if ($this->allow_owner_add_info) {
            array_push($title, $view->translate('Allow business owner to add Information Pages'));
        }
        if ($this->allow_owner_change_order) {
            array_push($title, $view->translate('Allow business owner to change orders of Pages'));
        }
        if ($this->allow_user_join_business) {
            array_push($title, $view->translate('Allow users to join Business'));
        }
        if ($this->allow_user_share_business) {
            array_push($title, $view->translate('Allow users to share Business'));
        }
        if ($this->allow_user_invite_friend) {
            array_push($title, $view->translate('Allow users to invite friends to Business'));
        }
        if ($this->allow_owner_add_contactform) {
            array_push($title, $view->translate('Allow business owner to add contact form'));
        }
        if ($this->allow_owner_add_customfield) {
            array_push($title, $view->translate('Allow business owner to add more custom fields to his Business'));
        }
        if ($this->allow_bussiness_multiple_admin) {
            array_push($title, $view->translate('Allow business to have multiple admins'));
        }
        return $title;
    }

    public function getAvailableModules() {
        $modules = array();
        $moduleTbl = Engine_Api::_()->getDbTable('modules', 'ynbusinesspages');
        $moduleTblName = $moduleTbl->info('name');
        $table = Engine_Api::_()->getDbTable('packagemodules', 'ynbusinesspages');
        $tableName = $table->info('name');
        $select = $table->select();
        $select->setIntegrityCheck(false);
        $select->from("$tableName", "$tableName.*");
        $select->joinLeft("$moduleTblName", "$moduleTblName.module_id = $tableName.module_id", "$moduleTblName.title as title");
        $select->where("$tableName.package_id = ?", $this->getIdentity());
        $rows = $table->fetchAll($select);
        foreach ($rows as $row) {
            array_push($modules, $row->title);
        }
        return $modules;
    }
}
